package wqh.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import wqh.domain.AlarmConfirm;

import java.util.List;

/**
 * Created by devts on 2016/9/28.
 */
public interface AlarmConfirmDao {

    @Insert("INSERT INTO alarm_confirm (geo_1_name, geo_2_name, geo_3_name, device_name, device_ip_str, sensor_name,monitor_id, monitor_name, dev_type, dev_addr, dev_status, confirm_status, confirm_time, alarm_time, phone, user) VALUES(" +
            "#{geo_1_name}, #{geo_2_name}, #{geo_3_name}, #{device_name}, #{device_ip_str}, #{sensor_name}, #{monitor_id}, #{monitor_name}, #{dev_type}, #{dev_addr}, #{dev_status}, #{confirm_status}, #{confirm_time}, #{alarm_time},#{phone},#{user})")
    int insertRecord(AlarmConfirm alarmConfirm);

    @Update("UPDATE alarm_confirm SET confirm_status = #{0}, confirm_time = #{1} WHERE id = #{2}")
    int updateConfirmStatus(Integer confirm_status, Integer confirm_time, Integer id);

    @Select("SELECT * FROM alarm_confirm ORDER BY alarm_time DESC")
    List<AlarmConfirm> findAllRecord();

    @Select("SELECT * FROM alarm_confirm WHERE confirm_status = #{1} ORDER BY alarm_time DESC")
    List<AlarmConfirm> findAllByConfirmStatus(Integer id);

    @Select("SELECT * FROM alarm_confirm WHERE alarm_time >= #{1}")
    List<AlarmConfirm> findAllByTimeTo(Integer unix_time);

    @Select("SELECT * FROM alarm_confirm WHERE id = #{1}")
    AlarmConfirm findAllById(Integer id);

    @Select("SELECT * FROM alarm_confirm WHERE alarm_time >= #{0} and confirm_status = #{1}")
    List<AlarmConfirm> findAllByTimeToAndConfirmStatus(Integer unix_time, Integer confirm_status);

    @Select("SELECT * FROM alarm_confirm WHERE alarm_time >= #{0} AND alarm_time <= #{1} ORDER BY alarm_time DESC")
    List<AlarmConfirm> findExportLog(Integer unix_time_start, Integer unix_time_end);

    List<AlarmConfirm> findByTimeRange(Integer start, Integer end);

    List<AlarmConfirm> findByTimeRangeAndType(String type,Integer start, Integer end);

    List<AlarmConfirm> findByStatus(String dev_status);

    int findAllCount(String dev_status);

    int deleteById(Integer id);


}
